package android.slc.appdb.utils;

import android.slc.appdb.sys.entity.CsDictData;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Filter;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class DictUtils {
    public static List<String> dictDataList2LabelList(List<CsDictData> csDictDataList) {
        List<String> labelList = new ArrayList<>();
        CollectionUtil.forEach(csDictDataList, new CollUtil.Consumer<CsDictData>() {
            @Override
            public void accept(CsDictData value, int index) {
                labelList.add(value.getDictLabel());
            }
        });
        return labelList;
    }

    public static String getLabelByValue(List<CsDictData> csDictDataList, String value) {
        CsDictData dictData = CollectionUtil.findOne(csDictDataList, new Filter<CsDictData>() {
            @Override
            public boolean accept(CsDictData csDictData) {
                return StringUtils.equals(csDictData.getDictValue(), value);
            }
        });
        if (dictData != null) {
            return dictData.getDictLabel();
        }
        return null;
    }
}
